<script setup lang="ts">
// 联系表单数据
const formData = reactive({
  name: '',
  email: '',
  phone: '',
  subject: '',
  message: ''
})

// 表单验证状态
const formErrors = reactive({
  name: '',
  email: '',
  message: ''
})

// 表单提交状态
const isSubmitting = ref(false)
const submitSuccess = ref(false)
const submitError = ref('')

// 表单验证
const validateForm = () => {
  let isValid = true
  
  // 重置错误信息
  Object.keys(formErrors).forEach(key => {
    formErrors[key] = ''
  })
  
  // 验证姓名
  if (!formData.name.trim()) {
    formErrors.name = '请输入您的姓名'
    isValid = false
  }
  
  // 验证邮箱
  if (!formData.email.trim()) {
    formErrors.email = '请输入您的邮箱地址'
    isValid = false
  } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
    formErrors.email = '请输入有效的邮箱地址'
    isValid = false
  }
  
  // 验证留言内容
  if (!formData.message.trim()) {
    formErrors.message = '请输入您的留言内容'
    isValid = false
  } else if (formData.message.trim().length < 10) {
    formErrors.message = '留言内容至少需要10个字符'
    isValid = false
  }
  
  return isValid
}

// 表单提交
const submitForm = async () => {
  // 验证表单
  if (!validateForm()) {
    return
  }
  
  // 设置提交状态
  isSubmitting.value = true
  submitError.value = ''
  
  try {
    // 模拟API请求
    await new Promise(resolve => setTimeout(resolve, 1500))
    
    // 提交成功
    submitSuccess.value = true
    
    // 重置表单
    Object.keys(formData).forEach(key => {
      formData[key] = ''
    })
    
    // 3秒后隐藏成功提示
    setTimeout(() => {
      submitSuccess.value = false
    }, 3000)
  } catch (error) {
    submitError.value = '提交失败，请稍后再试'
  } finally {
    isSubmitting.value = false
  }
}

// 联系信息
const contactInfo = [
  {
    title: '公司地址',
    content: '北京市海淀区中关村科技园区8号楼15层',
    icon: '📍'
  },
  {
    title: '联系电话',
    content: '400-123-4567',
    icon: '📞'
  },
  {
    title: '电子邮箱',
    content: 'contact@example.com',
    icon: '✉️'
  },
  {
    title: '工作时间',
    content: '周一至周五 9:00-18:00',
    icon: '⏰'
  }
]

// 社交媒体链接
const socialMedia = [
  { name: '微信', icon: '💬', url: '#' },
  { name: '微博', icon: '📱', url: '#' },
  { name: 'LinkedIn', icon: '🔗', url: '#' },
  { name: 'GitHub', icon: '💻', url: '#' }
]
</script>

<template>
  <div class="contact-page">
    <!-- 页面标题 -->
    <section class="page-header">
      <h1>联系我们</h1>
      <p>无论您有任何问题或建议，都欢迎随时与我们联系</p>
    </section>

    <!-- 联系信息 -->
    <section class="contact-info-section">
      <div class="contact-info-grid">
        <div 
          v-for="(info, index) in contactInfo" 
          :key="index" 
          class="card contact-info-card"
        >
          <div class="contact-icon">{{ info.icon }}</div>
          <h3>{{ info.title }}</h3>
          <p>{{ info.content }}</p>
        </div>
      </div>
    </section>

    <!-- 联系表单和地图 -->
    <section class="contact-form-section">
      <div class="contact-container">
        <!-- 联系表单 -->
        <div class="form-container">
          <div class="card form-card">
            <h2>发送留言</h2>
            
            <!-- 成功提示 -->
            <Transition name="fade">
              <div v-if="submitSuccess" class="success-message">
                ✅ 留言提交成功！我们会尽快与您联系
              </div>
            </Transition>
            
            <!-- 错误提示 -->
            <div v-if="submitError" class="error-message">
              ❌ {{ submitError }}
            </div>
            
            <form @submit.prevent="submitForm">
              <div class="form-group">
                <label for="name">姓名 *</label>
                <input
                  type="text"
                  id="name"
                  v-model="formData.name"
                  :class="{ 'error': formErrors.name }"
                  placeholder="请输入您的姓名"
                >
                <span v-if="formErrors.name" class="error-text">{{ formErrors.name }}</span>
              </div>
              
              <div class="form-group">
                <label for="email">邮箱 *</label>
                <input
                  type="email"
                  id="email"
                  v-model="formData.email"
                  :class="{ 'error': formErrors.email }"
                  placeholder="请输入您的邮箱地址"
                >
                <span v-if="formErrors.email" class="error-text">{{ formErrors.email }}</span>
              </div>
              
              <div class="form-group">
                <label for="phone">电话</label>
                <input
                  type="tel"
                  id="phone"
                  v-model="formData.phone"
                  placeholder="请输入您的联系电话（选填）"
                >
              </div>
              
              <div class="form-group">
                <label for="subject">主题</label>
                <input
                  type="text"
                  id="subject"
                  v-model="formData.subject"
                  placeholder="请输入留言主题（选填）"
                >
              </div>
              
              <div class="form-group">
                <label for="message">留言内容 *</label>
                <textarea
                  id="message"
                  v-model="formData.message"
                  :class="{ 'error': formErrors.message }"
                  placeholder="请详细描述您的问题或建议..."
                  rows="5"
                ></textarea>
                <span v-if="formErrors.message" class="error-text">{{ formErrors.message }}</span>
              </div>
              
              <button 
                type="submit" 
                class="submit-btn"
                :disabled="isSubmitting"
              >
                {{ isSubmitting ? '提交中...' : '提交留言' }}
              </button>
            </form>
          </div>
        </div>
        
        <!-- 地图和社交媒体 -->
        <div class="map-container">
          <!-- 地图占位 -->
          <div class="map-placeholder">
            <div class="map-content">
              <h3>我们的位置</h3>
              <p>北京市海淀区中关村科技园区8号楼15层</p>
              <div class="map-icon">🗺️</div>
              <button class="map-btn">查看地图</button>
            </div>
          </div>
          
          <!-- 社交媒体 -->
          <div class="card social-card">
            <h3>关注我们</h3>
            <div class="social-links">
              <a 
                v-for="(social, index) in socialMedia" 
                :key="index" 
                :href="social.url" 
                target="_blank"
                class="social-link"
              >
                <span class="social-icon">{{ social.icon }}</span>
                <span class="social-name">{{ social.name }}</span>
              </a>
            </div>
          </div>
        </div>
      </div>
    </section>

    <!-- 常见问题 -->
    <section class="faq-section">
      <div class="section-header">
        <h2>常见问题</h2>
        <p>您可能关心的问题</p>
      </div>
      <div class="faq-content">
        <div class="faq-item">
          <h3>如何申请产品演示？</h3>
          <p>您可以通过联系表单提交演示申请，或直接拨打我们的服务热线400-123-4567，我们的销售顾问会在1个工作日内与您联系，安排产品演示。</p>
        </div>
        <div class="faq-item">
          <h3>售后服务包含哪些内容？</h3>
          <p>我们提供7×24小时技术支持、系统维护、升级服务、培训服务等。具体服务内容可根据您购买的服务套餐有所不同，详情可咨询我们的客服人员。</p>
        </div>
        <div class="faq-item">
          <h3>可以定制开发吗？</h3>
          <p>是的，我们可以根据您的业务需求提供定制开发服务。请联系我们详细说明您的需求，我们的技术团队会评估可行性并提供定制方案。</p>
        </div>
      </div>
    </section>
  </div>
</template>

<style scoped>
.contact-page {
  width: 100%;
}

/* 页面标题 */
.page-header {
  text-align: center;
  margin-bottom: 60px;
  padding: 60px 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px;
  margin-top: 30px;
}

.page-header h1 {
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 15px;
}

.page-header p {
  font-size: 18px;
  opacity: 0.9;
}

/* 联系信息 */
.contact-info-section {
  margin-bottom: 80px;
}

.contact-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 30px;
}

.contact-info-card {
  text-align: center;
  padding: 30px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.contact-info-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 20px 30px rgba(0, 0, 0, 0.1);
}

.contact-icon {
  font-size: 48px;
  margin-bottom: 20px;
}

.contact-info-card h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 15px;
  color: #333;
}

.contact-info-card p {
  font-size: 16px;
  color: #666;
  line-height: 1.6;
}

/* 联系表单和地图 */
.contact-form-section {
  margin-bottom: 80px;
}

.contact-container {
  display: flex;
  flex-wrap: wrap;
  gap: 40px;
}

.form-container {
  flex: 1;
  min-width: 300px;
}

.form-card {
  padding: 40px;
}

.form-card h2 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 30px;
  color: #333;
  position: relative;
  display: inline-block;
}

.form-card h2::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 0;
  width: 60px;
  height: 4px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 2px;
}

/* 表单样式 */
.form-group {
  margin-bottom: 25px;
  position: relative;
}

.form-group label {
  display: block;
  font-size: 16px;
  font-weight: 500;
  color: #333;
  margin-bottom: 8px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s ease;
  background: white;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group input.error,
.form-group textarea.error {
  border-color: #ff4d4f;
}

.error-text {
  position: absolute;
  bottom: -20px;
  left: 0;
  font-size: 14px;
  color: #ff4d4f;
}

.submit-btn {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.submit-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

.submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* 成功和错误提示 */
.success-message {
  background: #f6ffed;
  border: 1px solid #b7eb8f;
  color: #52c41a;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
  text-align: center;
  font-size: 16px;
}

.error-message {
  background: #fff2f0;
  border: 1px solid #ffccc7;
  color: #ff4d4f;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
  text-align: center;
  font-size: 16px;
}

/* 地图和社交媒体 */
.map-container {
  flex: 1;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.map-placeholder {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  height: 350px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.map-placeholder::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('https://images.unsplash.com/photo-1516321497487-e288fb19713f?auto=format&fit=crop&q=80');
  background-size: cover;
  background-position: center;
  opacity: 0.2;
}

.map-content {
  position: relative;
  text-align: center;
  color: white;
  padding: 30px;
  max-width: 400px;
}

.map-content h3 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 15px;
}

.map-content p {
  font-size: 16px;
  margin-bottom: 25px;
  opacity: 0.9;
  line-height: 1.6;
}

.map-icon {
  font-size: 64px;
  margin-bottom: 25px;
  opacity: 0.9;
}

.map-btn {
  padding: 12px 30px;
  background: white;
  color: #667eea;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.map-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px rgba(255, 255, 255, 0.3);
}

.social-card {
  padding: 30px;
}

.social-card h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #333;
  text-align: center;
}

.social-links {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.social-link {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  color: #333;
  text-decoration: none;
  transition: all 0.3s ease;
}

.social-link:hover {
  border-color: #667eea;
  background: #f8f9ff;
  transform: translateX(5px);
}

.social-icon {
  font-size: 24px;
  margin-right: 15px;
}

.social-name {
  font-size: 16px;
  font-weight: 500;
}

/* 常见问题 */
.faq-section {
  margin-bottom: 60px;
}

.section-header {
  text-align: center;
  margin-bottom: 50px;
}

.section-header h2 {
  font-size: 32px;
  font-weight: 700;
  color: #333;
  margin-bottom: 15px;
  position: relative;
  display: inline-block;
}

.section-header h2::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 4px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 2px;
}

.section-header p {
  font-size: 16px;
  color: #666;
  max-width: 600px;
  margin: 0 auto;
}

.faq-content {
  max-width: 900px;
  margin: 0 auto;
}

.faq-item {
  margin-bottom: 30px;
  padding: 25px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
}

.faq-item h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 15px;
  color: #333;
}

.faq-item p {
  font-size: 16px;
  color: #666;
  line-height: 1.8;
}

/* 动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-header {
    padding: 40px 0;
  }
  
  .page-header h1 {
    font-size: 36px;
  }
  
  .form-card {
    padding: 30px 20px;
  }
  
  .form-card h2,
  .section-header h2 {
    font-size: 28px;
  }
  
  .map-placeholder {
    height: 280px;
  }
  
  .map-content h3 {
    font-size: 22px;
  }
  
  .map-icon {
    font-size: 48px;
  }
  
  .faq-item {
    padding: 20px;
  }
  
  .faq-item h3 {
    font-size: 18px;
  }
}
</style>